package system

import (
	"context"

	"go_admin/api/system/v1"
	"go_admin/internal/database/system/model/entity"
	"go_admin/internal/service"
)

func (c *ControllerV1) DeptList(ctx context.Context, req *v1.DeptListReq) (res *v1.DeptListRes, err error) {
	res = new(v1.DeptListRes)
	res.DeptList, err = service.SysDept().GetList(ctx, req)
	return
}
func (c *ControllerV1) DeptAdd(ctx context.Context, req *v1.DeptAddReq) (res *v1.DeptAddRes, err error) {
	err = service.SysDept().Add(ctx, req)
	return
}
func (c *ControllerV1) DeptEdit(ctx context.Context, req *v1.DeptEditReq) (res *v1.DeptEditRes, err error) {
	err = service.SysDept().Edit(ctx, req)
	return
}
func (c *ControllerV1) DeptDelete(ctx context.Context, req *v1.DeptDeleteReq) (res *v1.DeptDeleteRes, err error) {
	err = service.SysDept().Delete(ctx, req.Id)
	return
}
func (c *ControllerV1) DeptTreeSelect(ctx context.Context, req *v1.DeptTreeSelectReq) (res *v1.DeptTreeSelectRes, err error) {
	var deptList []*entity.SysDept
	deptList, err = service.SysDept().GetList(ctx, &v1.DeptListReq{
		Status: "1", //正常状态数据
	})
	if err != nil {
		return
	}
	res = new(v1.DeptTreeSelectRes)
	res.Deps = service.SysDept().GetListTree(0, deptList)
	return
}
